<template>
    <div>
      <el-form ref="ruleForm" :model="form"  label-width="100px">
  
        <el-row>
          <el-col :span="6" :offset="1">
            <el-form-item label="商品名称" prop="store_name">
              <el-input v-model="form.store_name"></el-input>
            </el-form-item>
            <el-form-item label="电话" prop="store_number">
              <el-input v-model="form.store_number"></el-input>
            </el-form-item>
            <el-form-item label="商品描述" prop="store_text" style="height: 60px;width: 300px;">
              <el-input type="textarea" v-model="form.store_text"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
  
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" @click="submit(ruleForm)">立即保存</el-button>
        <el-button @click="$emit('change', false)">取 消</el-button>
      </div>
  
  
    </div>
  </template>

<script>
export default {
    name:'CreateStoresView',
    data () {
        return {
        form: {
        store_id: 2,
        store_name:"xx",
        store_address:'xxx',
        store_number:'13398885666',
        store_text:"非常好"      
      }
        }
    },  model: {
    prop: "dialogFormVisible",
    event: "change",
  },methods:{
   submit(){
    this.axios({  
                method: "post",  
                url: "stores",  
                data: JSON.stringify(this.form),  
                headers: {  
                    'Content-Type': 'application/json',  
                }  
            }).then(res => {  
                if (res.data.code>0) {  
                    this.$notify({  
                        title: '添加成功!',  
                        message: '这是一条成功的提示消息',  
                        type: 'success'  
                    });  

                     //刷新主页面数据
                this.$emit("refresh");
                //关闭弹窗
                this.$emit("change", false);  
                } else {  
                    this.$notify.error({  
                        title: '添加失败!',  
                        message: '这是一条错误的提示消息'  
                    });  
                }  
            }).catch(err => {  
                console.error("请求失败:" + err);  
                
            });  
   }
    }
}
</script>
<style scoped>
.demo-ruleForm {
  padding: 20px;
  border: 1px solid #e4e7ed;
  border-radius: 5px;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.store-form {
    border: 1px solid #e4e7ed;
    border-radius: 4px;
    padding: 20px;
    margin-bottom: 20px;
}
.dialog-footer {
    padding: 10px;
    border-top: 1px solid #e4e7ed;
}
  </style>